package a07_二叉树;

/**
 * <p>
 * a33_把二叉搜索树转换为累加树复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/4/25
 */
public class a33_把二叉搜索树转换为累加树复习2 {

    public TreeNode convertBST(TreeNode root) {
        traversal(root);
        return root;
    }

    private TreeNode prevNode;

    private void traversal(TreeNode curNode){
        if (curNode == null) {
            return;
        }

        traversal(curNode.right);

        if(prevNode != null){
            curNode.val = prevNode.val + curNode.val;
        }
        prevNode = curNode;

        traversal(curNode.left);
    }
}
